package ltd.itlover.yqblog.main;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.Toast;

import ltd.itlover.yqblog.R;
import ltd.itlover.yqblog.application.MyApplication;
import ltd.itlover.yqblog.blog.EditBlogActivity;
import ltd.itlover.yqblog.blog.MainActivity;
import ltd.itlover.yqblog.intent.IntentToLogin;
import ltd.itlover.yqblog.utils.AccountUtil;

/**
 * A simple {@link Fragment} subclass.
 * create an instance of this fragment.
 */
public class ForumFragment extends Fragment {

    View view;
    ImageButton btnEditBlog;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_forum, container, false);

        init();
        return view;
    }

    void init(){

        btnEditBlog = (ImageButton) view.findViewById(R.id.btn_edit_blog);
        btnEditBlog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //打开博客编辑界面
                Intent intent = new Intent(MainActivity.getMainContext(), EditBlogActivity.class);
                if(!AccountUtil.ifLogin()){
                    makeInfo("请先登录再操作");
                    IntentToLogin.toLoginPage();
                }
                else{
                    MainActivity.getMainContext().startActivity(intent);
                }

            }
        });
    }

    void makeInfo(String msg){
        Toast.makeText(MyApplication.getContext(), msg, Toast.LENGTH_SHORT).show();
    }
}